export default {
	timestampToTime(timestamp) {
		var date = new Date(timestamp * 1000);
		var Y = date.getFullYear() + '-';
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
		var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
		var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
		var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
		var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
		return Y + M + D + '  ' + h + ':' + m + ':' + s;
	},
	threadTime(timestamp) {
		var result;
		var timePublish = new Date(timestamp * 1000);
		var timeNow = new Date();
		var minute = 1000 * 60;
		var hour = minute * 60;
		var day = hour * 24;
		var month = day * 30;
		var diffValue = timeNow - timePublish;
		var diffMonth = diffValue / month;
		var diffWeek = diffValue / (7 * day);
		var diffDay = diffValue / day;
		var diffHour = diffValue / hour;
		var diffMinute = diffValue / minute;
		if(diffValue <= 0) {
			result = '刚刚发表';
		} else if(diffMonth > 3) {
			result = timePublish.getFullYear() + "-";
			result += timePublish.getMonth() + "-";
			result += timePublish.getDate();
		} else if(diffMonth > 1) {
			result = parseInt(diffMonth) + "月前";
		} else if(diffWeek > 1) {
			result = parseInt(diffWeek) + "周前";
		} else if(diffDay > 1) {
			result = parseInt(diffDay) + "天前";
		} else if(diffHour > 1) {
			result = parseInt(diffHour) + "小时前";
		} else if(diffMinute > 1) {
			result = parseInt(diffMinute) + "分钟前";
		} else {
			result = "刚刚发表";
		}
		return result;
	},
	back: function() {
		window.history.go(-1);
	},
			//封装获取传入值的下标
	arrIndex: function(arr, value) {
		var len = arr.length;
		for(var i = 0; i < len; i++) {
			if(arr[i] == value) {
				return i
			}
		}
		return false;
	},
	//	Date.prototype.Format = function(fmt) {
	//				var o = {
	//					"M+": this.getMonth() + 1,
	//					"d+": this.getDate(),
	//					"h+": this.getHours(),
	//					"m+": this.getMinutes(),
	//					"s+": this.getSeconds(),
	//					"q+": Math.floor((this.getMonth() + 3) / 3),
	//					"S": this.getMilliseconds()
	//				};
	//				if(/(y+)/.test(fmt))
	//					fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	//				for(var k in o)
	//					if(new RegExp("(" + k + ")").test(fmt))
	//						fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	//				return fmt;
	//			}
	//timer2time: function(time) {
	//				return new Date(parseInt(time) * 1000).Format("yyyy-MM-dd hh:mm:ss");
	//			},
}